/*根据老的state和指定的action生成并返回新的state的函数*/
import {combineReducers} from 'redux'
import store from "./store"; //用于合并多个reducer为一个，没有多个reducer则直接导出对应函数即可
const defaultState = {
    moduleId: null,
    moduleType: null
}

export default (state = defaultState,action) => {
    if(action.type == "action"){
        console.log("action:",action)
        let newState = JSON.parse(JSON.stringify(state));
        newState.moduleId = action.moduleId;
        newState.moduleType = action.moduleType;
        newState.path = action.path;
        newState.status = action.status;
        console.log("newState:",newState)
        return newState
    }
    if(action.type == "manage"){
        let newState = JSON.parse(JSON.stringify(state));
        console.log("action.path:",action.path)
        newState.path = action.path;
        console.log("newState:",newState)
        return newState
    }
    if(action.type == "sessionBox"){
        let newState = JSON.parse(JSON.stringify(state));
        newState.visible = action.visible;
        console.log("newState:",newState)
        return newState
    }
    if(action.type=="addButton"){
        let newState = JSON.parse(JSON.stringify(state));
        newState.lock = action.lock;
        newState.value = action.value;
        console.log("newState:",newState)
        return newState
    }
    if(action.type == "menu"){
        console.log("menu type:",typeof action.menu)
        let newState = JSON.parse(JSON.stringify(state))
        newState.menu = action.menu
        console.log("newState:",newState)
        return newState
    }
    if(action.type == "pushUrl"){
        let newState = JSON.parse(JSON.stringify(state))
        newState.url = action.url
        console.log("newState:",newState)
        return newState
    }
    if(action.type=="closeStatus"){
        let newState = JSON.parse(JSON.stringify(state));
        newState.status = action.status;
        return newState
    }
    if(action.type=="openStatus"){
        let newState = JSON.parse(JSON.stringify(state));
        newState.status = action.status;
        return newState
    }
    if(action.type=="closeRoleAdminStatus"){
        let newState = JSON.parse(JSON.stringify(state));
        newState.closeRoleAdminStatus = action.closeRoleAdminStatus;
        return newState
    }
    if(action.type=="closeRoleClientStatus"){
        let newState = JSON.parse(JSON.stringify(state));
        newState.closeRoleClientStatus = action.closeRoleClientStatus;
        return newState
    }
    if(action.type=="modalRef"){
        let newState = JSON.parse(JSON.stringify(state));
        newState.container = action.container;
        return newState
    }
    if(action.type=="breadCrumbList"){
        let newState = JSON.parse(JSON.stringify(state))
        newState.breadCrumbList = action.breadCrumbList
        return newState
    }
    if(action.type=="addBreadCrumbList"){
        let flag = true
        let newState = JSON.parse(JSON.stringify(state))
        let list = [];
        for(let i=0;i<newState.breadCrumbList.length;i++){
            console.log(newState.breadCrumbList.length)
            if(flag==false){
                break
            }
            let item = newState.breadCrumbList[i];
            if(item.parentId == action.addBreadCrumbList.parentId){
                flag = false
                list = list.concat(action.addBreadCrumbList)
            }
            else{
                flag = true
                list = list.concat(item)
            }
        }
        if(flag){
            list.push(action.addBreadCrumbList)
        }
        newState.breadCrumbList = list
        return newState
    }
    if(action.type=="inserted"){
        let newState = JSON.parse(JSON.stringify(state))
        newState.inserted = action.inserted
        return newState
    }
    return state
}
